/**
 * Created by gongxun on 16/11/15.
 */

var KwxppJoinFreeResponsekwxpp = function(){
    var that = new GameResponseBase();

    that.handle = function (binary, msgid) {
        that.loadMessage(binary, msgid);
        that.msg = mo.gameHelper.replaceJsonTokwx(that.msg, {});
        that.log();

        mo.closeWaitLayer();

        var code = that.msg.code;

        //代开房
        if (code == 0 && that.msg.min_coins != null && that.msg.min_coins != 0){
            mo.showMsgDialogOkAndCancel("为好友代开房成功！\n房间号:" + that.msg.min_coins, function(){
                mo.eventHelper.dispatch("showRoomYilaiLayer");
            }, mo.sceneMainLayer, function(){

            }, mo.sceneMainLayer);
            return;
        }

        if (code == 0){
                //游戏模式2人
                mo.gameMsgManager.kwxGameModel = 2;

                //进入牌桌
                mo.sceneHelper.runSceneKwx();
                mo.kwxTable.loadPlayCard();

                //牌桌密码
                var tablePassWord = that.msg.TablePassWord;

                //包房名称
                var GroupName = that.msg.GroupName;

                //游戏设置
                mo.kwxTable.setKwxConfig(that.msg.CfgJson, tablePassWord, GroupName);

                //是否是房主
                mo.kwxTable.mIsRoomCreator = (that.msg.CreateUid == mo.gameUserInfo.uid);

                //是否是代开
                mo.kwxTable.setShowRoomCreate(that.msg.CreateUser);

                //短线重连重新绘制牌桌
                var game_stats = that.msg.game_stats;
                if (game_stats != null) {
                    mo.kwxTableStatus.setReconnectStatus(game_stats);
                }

        }else if (code == 2){
            mo.showRoomMsgShow("抱歉，您代开房的房间数量已达到上限");
        }else if (code == 3){
            mo.showRoomMsgShow("该局已经开始，不能加入");
        }else if (code == 5){
            mo.showRoomMsgShow("加入牌局失败，牌桌号不存在");
        }else if (code == 6){
            mo.showRoomMsgShow("加入牌局失败，密码错误");
            mo.eventHelper.dispatch("JoinFreeResponse_error_code6");
        }else if (code == 7) {
            //other
            mo.showRoomMsgShow("加入牌局失败，号码错误或者房间人数已满");
        }else if (code == 8){
            mo.showRoomMsgShow("创建牌局失败，包房卡不足");
        }else{
            mo.showRoomMsgShow("error code=" + code);
        }

        //通知加入房间结果
        mo.eventHelper.dispatch_1("msg_joinFreeTableStatus", code == 0);

        //关闭等待
        mo.eventHelper.dispatch("closeWaitCreateTableLayer");
    };

    return that;
};